//
//  HeaderCollectionReusableView.m
//  14-UI-Gift
//
//  Created by Snow on 16/8/2.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "HeaderCollectionReusableView.h"
#import "YouCollectionViewCell.h"
#define kReuse @"collectionViewCell"
@interface HeaderCollectionReusableView ()<UICollectionViewDelegate, UICollectionViewDataSource>

@end
@implementation HeaderCollectionReusableView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UITextField *text = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(frame), 20)];
        text.placeholder = @"快速搜索你想要的礼物";
        text.borderStyle = 2;
        text.textAlignment = 1;
        _leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, frame.size.width / 2, 50)];
        _leftLabel.text = @"栏目";
        _rightLabel = [[UILabel alloc] initWithFrame:CGRectMake(frame.size.width / 2, 20, frame.size.width / 2, 50)];
        _rightLabel.text = @"查看全部 >";
        _rightLabel.textAlignment = 2;
        [self addSubview:text];
        [self addSubview:_leftLabel];
        [self addSubview:_rightLabel];
        
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.itemSize = CGSizeMake(frame.size.width / 1.2, (frame.size.height - 50 - 20 - 10) / 3);
        layout.minimumInteritemSpacing = 0;
        layout.minimumLineSpacing = 5;
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        layout.sectionInset = UIEdgeInsetsMake(0, 5, 0, 5);
        UICollectionView *collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 50, frame.size.width, frame.size.height - 50 - 20) collectionViewLayout:layout];
        collection.delegate = self;
        collection.dataSource = self;
        [self addSubview:collection];
        collection.backgroundColor = [UIColor whiteColor];
        [collection registerClass:[YouCollectionViewCell class] forCellWithReuseIdentifier:kReuse];
    }
    return self;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 12;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    YouCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kReuse forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    return cell;
}
@end
